package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiSubsidyApplication;
import com.minimalist.common.entity.lindi.vo.subsidyapplication.LindiSubsidyApplicationQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;

import java.util.List;

/**
 * 林地指标交易平台_补贴申请表 映射层。
 *
 * @author 11987
 * @since 2025-06-09
 */
public interface LindiSubsidyApplicationMapper extends BaseMapper<LindiSubsidyApplication>{

    /**
     * 根据ID查询补贴申请
     *
     * @param subsidyApplicationId 补贴申请ID
     * @return 补贴申请
     */
    default LindiSubsidyApplication selectSubsidyApplicationBySubsidyApplicationId(Long subsidyApplicationId){
        return selectOneByQuery(QueryChain.create().eq(LindiSubsidyApplication::getSubsidyApplicationId, subsidyApplicationId));
    }

    /**
     * 分页查询补贴申请列表
     *
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiSubsidyApplication> selectPageSubsidyApplicationList(LindiSubsidyApplicationQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .eq(LindiSubsidyApplication::getEnterpriseAccountId, queryVO.getEnterpriseAccountId())
                        .like(LindiSubsidyApplication::getProjectName, queryVO.getProjectName())
                        .eq(LindiSubsidyApplication::getSubsidyStatus, queryVO.getSubsidyStatus())
                        .ge(LindiSubsidyApplication::getAcceptDate, queryVO.getStartDate())
                        .le(LindiSubsidyApplication::getAcceptDate, queryVO.getEndDate())
                        .orderBy(LindiSubsidyApplication::getCreateTime, false));
    }

    /**
     * 根据企业账号ID查询补贴申请列表
     *
     * @param enterpriseAccountId 企业账号ID
     * @return 补贴申请列表
     */
    default List<LindiSubsidyApplication> selectSubsidyApplicationListByEnterpriseAccountId(
            Long enterpriseAccountId){
        return selectListByQuery(QueryChain.create()
                .eq(LindiSubsidyApplication::getEnterpriseAccountId, enterpriseAccountId)
                .orderBy(LindiSubsidyApplication::getCreateTime, false));
    }

    /**
     * 根据补贴状态查询补贴申请列表
     *
     * @param subsidyStatus 补贴状态
     * @return 补贴申请列表
     */
    default List<LindiSubsidyApplication> selectSubsidyApplicationListBySubsidyStatus(
            String subsidyStatus){
        return selectListByQuery(QueryChain.create()
                .eq(LindiSubsidyApplication::getSubsidyStatus, subsidyStatus)
                .orderBy(LindiSubsidyApplication::getCreateTime, false));
    }
}